import java.util.*;

public class League {
    private Map<String, Team> teams;

    public League(List<String> teamNames) {
        teams = new HashMap<>();
        for (String name : teamNames) {
            teams.put(name, new Team(name));
        }
    }

    public void updateResults(String homeTeam, String awayTeam, int homeScore, int awayScore) {
        Team home = teams.get(homeTeam);
        Team away = teams.get(awayTeam);

        if (home != null && away != null) {
            home.updateStats(homeScore, awayScore);
            away.updateStats(awayScore, homeScore);
        }
    }

    public List<Team> getStandings() {
        List<Team> standings = new ArrayList<>(teams.values());
        Collections.sort(standings);
        return standings;
    }
}

